﻿/*
 * SystemInfoSnapshot
 * Author: Tiago Conceição
 * 
 * http://systeminfosnapshot.com/
 * https://github.com/sn4k3/SystemInfoSnapshot
 */

using System;
using System.Linq;
using SystemInfoSnapshot.Extensions;

namespace SystemInfoSnapshot.Core.Malware
{
    public sealed class MalwareItem
    {
        #region Properties
        /// <summary>
        /// Gets or sets the malware name
        /// </summary>
        public string Name { get; set; }

        /// <summary>
        /// Gets or sets the malware type
        /// </summary>
        public MalwareType Type { get; set; }

        /// <summary>
        /// Gets or sets if this malware must exactly match with a software name or only need to contains all words in it
        /// </summary>
        public bool ExactMatch { get; set; }
        #endregion

        #region Constructor
        public MalwareItem()
        {
        }

        public MalwareItem(string name, MalwareType type, bool exactMatch = false)
        {
            Name = name;
            Type = type;
            ExactMatch = exactMatch;
        }
        #endregion

        # region Overrides
        public override string ToString()
        {
            return string.Format("Name: {0}, Type: {1}", Name, Type);
        }

        private bool Equals(MalwareItem other)
        {
            return string.Equals(Name, other.Name);
        }

        public override bool Equals(object obj)
        {
            if (ReferenceEquals(null, obj)) return false;
            if (ReferenceEquals(this, obj)) return true;
            return obj is MalwareItem && Equals((MalwareItem) obj);
        }

        public bool Equals(string name)
        {
            return ExactMatch ? Name.Equals(name) : Name.Split(' ').All(word => name.Contains(word, StringComparison.OrdinalIgnoreCase));
        }

        public override int GetHashCode()
        {
            return (Name != null ? Name.GetHashCode() : 0);
        }
        #endregion
    }
}
